package cn.wolfcode.trip.app.controller;


import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.query.StrategyQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyDetailService;
import cn.wolfcode.trip.base.service.IStrategyService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("strategies")
public class StrategyController {

    @Autowired
    private IStrategyService strategyService;

    @Autowired
    private IStrategyCatalogService catalogService;

    @Autowired
    private IStrategyDetailService detailService;

    /**
     * 获取攻略资源
     * @return
     */
    @RequestMapping(method= RequestMethod.GET)
    public PageInfo query(StrategyQueryObject qo){
        return strategyService.queryForList(qo);

    }


    /**
     *  根据攻略id查询大攻略信息
      * @param id
     *  @return
     */
    @RequestMapping(value = "/{id}",method= RequestMethod.GET)
    public Strategy getById(@PathVariable Long id){
        return strategyService.getById(id);
    }

    /**
     * 根据攻略id查询攻略分类信息
     * @param id
     * @return
     * 代理对象转成Json时序列化会出现问题
     */
    @RequestMapping(value = "/{id}/catalogs",method= RequestMethod.GET)
    public List<StrategyCatalog> listCatalogByStrategyId(@PathVariable Long id){
        List<StrategyCatalog> catalogs = catalogService.listByStrategyId(id);
        return catalogs;
    }

    /**details
     * 根据攻略文章id查询文章信息
     * @param id
     * @return
     * 代理对象转成Json时序列化会出现问题
     */
    @RequestMapping(value = "/details/{id}",method= RequestMethod.GET)
    public StrategyDetail getByDetailId(@PathVariable Long id){

        return detailService.getByDetailId(id);
    }


}

